<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">


    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>渠道 <small>列表</small></h5>
                </div>
                <div class="ibox-content">
                    <table class="table table-bordered text-center">
                        <thead class="text-center">
                        <tr>
                            <th>渠道代码</th>
                            <th>合作方式</th>
                            <th>合作目标</th>
                            <th>预期效果</th>
                            <th>渠道状态</th>
                            <th>审核状态</th>
                            <th>总成交金额</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($channel_list as $channel)
                            <tr>
                                <td>{{$channel['channel_code']}}</td>
                                <td>{{$channel['cooperation']['name']}}</td>
                                <td>{{$channel['target']['name']}}</td>
                                <td>{{$channel['expections']}}</td>
                                <td>{{$channel['check_status']['name']}}</td>
                                <td>
                                    <select class="_open_status" data-id="{{ $channel['id'] }}">
                                        @foreach($open_status as $v)
                                            <option value="{{ $v['id'] }}"
                                                @if($v['id'] == $channel['open_status']['id']) selected @endif>
                                                {{ $v['name'] }}</option>
                                        @endforeach
                                    </select>
                                </td>
                                <td>{{$channel['invest_num']}}</td>
                                <td>
                                    <a href="/ceb/channels/check?channel_id={{ $channel['id'] }}">审核</a>
                                    @if($channel['check_status']['id'] == \App\Constants\ChannelCheckStatus::PASS)
                                        @if($channel['settlement_status'] == \App\Constants\ChannelSettlementStatus::UNSETTLED)
                                            | <a href="javascript:;" class="_fund" data-id="{{ $channel['id'] }}">结算</a>
                                        @endif
                                        | <a href="javascript:;" class="_mark" data-id="{{ $channel['id'] }}">备注</a>
                                        | <a href="/ceb/channels/daily?channel_id={{$channel['id']}}">数据跟踪</a>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    @include('wiget.pager',[
                        'page' => $page,
                        'page_size' => $page_size,
                        'count' => $count,
                        'show_count' => 10,
                        'path' => url('/ceb/channels/index?channel_provider_id=' . $channel_provider_id)
                    ])
                    <a class="btn btn-sm btn-primary" href="/ceb/channels/create?channel_provider_id={{ $channel_provider_id }}">添加渠道代码</a>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="settle_dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">费用结算</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered text-center">
                    <thead class="text-center">
                    <tr>
                        <th>合同类型</th>
                        <th>合同金额</th>
                        <th>实际结算金额</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="contract_type"></td>
                            <td class="contract_amount"></td>
                            <td><input type="text" class="pay_amount form-control"></td>
                            <td><input type="text" class="_mark form-control"></td>
                            <td><button class="btn btn-primary btn_save">保存</button></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/jquery.cookie.js"></script>
<!-- 自定义js -->
<script src="/js/content.js?v=1.0.0"></script>

<!-- iCheck -->
<script src="/js/plugins/iCheck/icheck.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>
<script src="/js/common.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        $('._open_status').on('change',function(){
            var id = $(this).data('id');
            var status = $(this).val();
            toAjax('/ceb/channels/openstatus',{channel_id:id,status:status},'POST')
                    .on('hxop.ajax-success',function(evt,data){
                        parent.layer.msg('成功!');
                    });
        });
        $('._fund').on('click',function(){
            var id = $(this).data('id');
            toAjax('/ceb/channels/show',{id:id},'GET')
                    .on('hxop.ajax-success',function(evt,data){
                        showSettleDialog(id,data.contract_type,data.contract_amount);
                    });
        });

        function showSettleDialog(id,contract_type,contract_amount){
            var dom = $('#settle_dialog');
            $('.contract_type',dom).html(contract_type);
            $('.contract_amount',dom).html(contract_amount);
            $('.btn_save',dom).off('click').on('click',function(){
                var pay_amount = $('.pay_amount',dom).val();
                var mark = $('._mark',dom).val();
                toAjax('/ceb/channels/settle',{id:id,pay_amount:pay_amount,settlement_mark:mark},'POST')
                        .on('hxop.ajax-success',function(){
                            layer.msg('成功!');
                            location.reload();
                        });
            });
            dom.modal();
        }
    });
</script>

</body>

</html>
